package controller;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.RejectDAO;
import dao.ReturnDAO;
import dao.StockDAO;

/**
 * Servlet implementation class SaveController
 */
public class SaveController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SaveController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String stockCode=request.getParameter("stockCode");
		String type = request.getParameter("type");
		String creator = new String(request.getParameter("creator").getBytes("ISO-8859-1"),"UTF-8");
		String id = request.getParameter("id");
		if(type.equals("stock")){
			new StockDAO().updateCodeAndCreator(stockCode, creator, id);
		}
		if(type.equals("reject")){
			new RejectDAO().updateCodeAndCreator(stockCode, creator, id);
		}
		if(type.equals("return")){
			new ReturnDAO().updateCodeAndCreator(stockCode, creator, id);
		}
		System.out.println("修改成功");
		String message = URLEncoder.encode("修改成功", "UTF-8");
		response.sendRedirect("./view/error.jsp?errorInfo="+message+"&redirect=./xiugai.jsp");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
